package com.zhou.syt.cmn.controller;

import com.atguigu.yygh.model.cmn.Dict;
import com.zhou.syt.cmn.service.DictService;
import com.zhou.syt.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @ClassName: DictController
 * @Description:
 * @Author: admin
 * @Date: 2021/12/14 13:44
 */
@RequestMapping("/admin/cmn/dict")
@RestController
@Api(value = "通用配置接口模块")
@CrossOrigin
public class DictController {

    @Resource
    private DictService dictService;

    //导入数据字典
    @PostMapping("/importData")
    @ApiOperation("导入数据")
    public Result importDict(MultipartFile file) {
        dictService.importDictData(file);
        return Result.ok();
    }

    //导出数据接口
    @GetMapping("/exportData")
    @ApiOperation("数据导出")
    public Result exportDict(HttpServletResponse response) {
        dictService.exportDict(response);
        return Result.ok();
    }

    @GetMapping(value = "/findChildData/{id}")
    @ApiOperation(value = "根据父id查询子列表数据")
    public Result findChildData(@PathVariable Long id) {
        List<Dict> list = dictService.findChildData(id);
        return Result.ok(list);
    }

    //根据dictcode和value进行查询
    @GetMapping("/getName/{dictCode}/{value}")
    public String getName(@PathVariable String dictCode,
                          @PathVariable String value) {
        String dictName=dictService.getDictName(dictCode,value);
        return dictName;
    }

    //根据value进行查询
    @GetMapping("/getName/{value}")
    public String getName(@PathVariable String value) {
        String dictName=dictService.getDictName("",value);
        return dictName;
    }
}
